<template>
<Timeline>
    <Alert v-if="errors.length>0" type="warning" show-icon>
        <p v-for="(error, index) in errors" :key="index">{{error}}</p>
    </Alert>
    <TimelineItem v-for="(item, index) in logs" :key="index" color="green">
        <Icon type="ios-arrow-dropup-circle" slot="dot"></Icon>
        <span mgr2>{{item.time}}</span>
        <span>{{item.description}}</span>
    </TimelineItem>
</Timeline>
</template>

<script lang="ts">
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
import OrderBase from './OrderBase';

@Component({})
export default class OrderWuliu extends OrderBase{
    @Prop() orderNumber:any;
	logs = []
    errors= []
	async getLogs(orderNumber) {
		var response1 = await this.get('AdminOrderManager/GetAllOrderLogs', { orderNumber: orderNumber });
		if(!response1.success) return [];
		var response2 = await this.get('AdminOrderManager/GetOrderWuliu', { orderNumber: orderNumber });
		if(!response2.success) return [];
		if(response2.result.error) {
			this.errors = response2.result.errors;
		}

		var arr1 = response1.result.map(elem => {
			return {
				_time: new Date(elem.creationTime).getTime(),
				time: this.formatTimeStr(elem.creationTime),
				description: elem.description
			}
		});
		var arr2 = response2.result.items.map(elem => {
			return {
				_time: new Date(elem.time).getTime(),
				time: this.formatTimeStr(elem.time),
				description: elem.description
			}
		}) || [];

		var arr = arr1.concat(arr2);
		this.logs = arr.sort((a, b) => {
			return b._time - a._time;
		});
    }
	async created() {
        await this.getLogs(this.orderNumber);
	}
}
</script>